package top.hkyzf.study.leetcode.array;

import org.junit.Test;

/**
 * description:
 *
 * @author zhufeng
 * @version 1.0
 * @date 2024-3-16 22:33
 */
public class 求出加密整数的和_100262 {
    public int sumOfEncryptedInt(int[] nums) {
        int rtn = 0;
        for (int num : nums) {
            rtn += encrypt(num);
        }
        return rtn;
    }

    private int encrypt(int x) {
        int max = 0;
        int index = 0;
        while (x != 0) {
            int tmp = x % 10;
            max = Math.max(max, tmp);
            x = x / 10;
            index++;
        }
        int rtn = 0;
        for (int i = 0; i < index; i++) {
            rtn += max * Math.pow(10, i);
        }
        return rtn;
    }

    @Test
    public void testSumOfEncrypt () {
        int[] nums = {10,21,31};
        System.out.println(sumOfEncryptedInt(nums));
    }
}
